<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        border: 25px solid gray;
        padding: 20px;
        background: yellow;
        background-clip: content-box;
        height: 400px;
        overflow: auto;
      }

      #box p {
        height: 400px;
        width: 800px;
      }
    </style>
  </head>
  <body style="padding: 20px">
    <div style="padding: 40px; position: relative">
      <div id="box">
        <p>hello box</p>
        <p>hello box</p>
        <p>hello box</p>
        <p>hello box</p>
      </div>
    </div>
    <script>
      const box = document.getElementById("box");
      console.log(box.offsetWidth, box.clientWidth);
      console.log(box.offsetHeight, box.clientHeight);

      console.log("内容高度：", box.scrollHeight);
      console.log("内容高度：", box.scrollWidth);

      // 相对父元素
      console.log("顶部间距：", box.offsetTop);
      console.log("左边间距：", box.offsetLeft);

      setTimeout(() => {
        console.log("顶部滚出距离：", box.scrollTop);
        console.log("左边滚出距离：", box.scrollLeft);
      }, 3000);

      // console.log(box.clientLeft); // 左边框的宽度
      // console.log(box.clientTop); //上边框的宽度
    </script>
  </body>
</html>
